#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int dis[N];
void dijkstra(int s) {
  memset(dis, 0x3f, sizeof(dis));
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push(pii(0, s));
  dis[s] = 0;
  while (pq.size()) {
    pii now = pq.top();
    pq.pop();
    int d = now.first;
    int u = now.second;
    if (d != dis[u]) continue;
    for (int i = head[u]; i; i = Next[i]) {
      int v = ver[i];
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        pq.push(pii(dis[v], v));
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  dijkstra(1);
  int mx = 1;
  rep(i, 1, n) if (dis[i] > dis[mx]) mx = i;
  dijkstra(mx);
  cout << *max_element(dis + 1, dis + n + 1);
  return 0;
}